﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace WpfApp55.ValidationRules
{
    public class TextValidationRule : ValidationRule
    {
        public int Max { get; set; } = Int32.MaxValue;
        public int Min { get; set; } = 0;

         public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value is string txt)
            {
                if (string.IsNullOrEmpty(txt))
                {
                    return new ValidationResult(false, "Error : Text is Null!");
                }

                if (txt.Length < Min)
                {
                    return new ValidationResult(false, $"Error : Text Length < {Min}!");
                }


                if (txt.Length > Max)
                {
                    return new ValidationResult(false, $"Error : Text Length > {Max}!");
                }

                return new ValidationResult(true, null);
            }
            else
            {
                return new ValidationResult(false, "Value is not String!");
            }


        }
    }
}
